1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package com.google.common.collect;
16
17 import com.google.common.annotations.GwtCompatible;
18
19 import java.io.Serializable;
20
21 import javax.annotation.Nullable;
22
23
24
25
26
27
28 @GwtCompatible
29 final class Count implements Serializable {
30 private int value;
31
32 Count(int value) {
33 this.value = value;
34 }
35
36 public int get() {
37 return value;
38 }
39
40 public int getAndAdd(int delta) {
41 int result = value;
42 value = result + delta;
43 return result;
44 }
45
46 public int addAndGet(int delta) {
47 return value += delta;
48 }
49
50 public void set(int newValue) {
51 value = newValue;
52 }
53
54 public int getAndSet(int newValue) {
55 int result = value;
56 value = newValue;
57 return result;
58 }
59
60 @Override
61 public int hashCode() {
62 return value;
63 }
64
65 @Override
66 public boolean equals(@Nullable Object obj) {
67 return obj instanceof Count && ((Count) obj).value == value;
68 }
69
70 @Override
71 public String toString() {
72 return Integer.toString(value);
73 }
74 }